#include <stdio.h>
#include <stdlib.h>
#include <assert.h>

#include "../../src/cdslib.h"

#define LENGTH 10

/*
 * Testing get(), as well as prints the Vector
 * for debugging of other functions 
 */
void printVector(Vector v) 
{
    int i;
    for(i = 0; i < v.length; i++) {
        printf("%d ", (int)VectorGet(&v, i));
    }
    printf("\n");
}

void *cast(size_t i)
{
    return (void *)i;
}

int main()
{
    int i;
    Vector v;
    initVector(&v);

    /* Testing add */
    for(i = 0; i < 20; i++) {
        VectorAdd(&v, cast(2*i));
    }
    printVector(v);

    /* Testing length */
    assert(v.length == 20);

    /* Testing set */
    for(i = 0; i < v.length; i++) {
        VectorSet(&v, i, cast(3*i));
    }
    printVector(v);

    /* Testing return value of set */
    assert(VectorSet(&v, 4, cast(100)) == cast(12));

    /* Testing insert at end */
    VectorInsert(&v, v.length, cast(101));
    printVector(v);

    /* Testing insert at beginning */
    VectorInsert(&v, 0, cast(102));
    printVector(v);

    /* Testing insert in the middle somewhere */
    VectorInsert(&v, 5, cast(103));
    printVector(v);

    /*
     * Testing insert bounds check at the final index + 1,
     * and far past the final index
     */
    VectorInsert(&v, v.length + 1, cast(13));
    VectorInsert(&v, 100001, cast(13));

    /* Testing extract at beginning*/
    assert(VectorExtract(&v, 0) == (void *)102);
    printVector(v);

    /* Testing extract at the end */
    assert(VectorExtract(&v, v.length - 1) == (void *)101);
    printVector(v);

    /* Testing extract in the middle somewhere */
    assert(VectorExtract(&v, 5) == (void *)100);
    printVector(v);

    /*
     * Testing extract bounds check at the final index + 1,
     * and far past the final index
    */
    VectorExtract(&v, v.length);
    VectorExtract(&v, 1001);

    /* Doing one last length check */
    assert(v.length == 20);

    deleteVector(&v);
    return EXIT_SUCCESS;
}
